package com.classroompie.classroompieserver.controller;

import com.classroompie.classroompiecommon.result.Result;
import com.classroompie.classroompiepojo.request.AddHomeWorkInput;
import com.classroompie.classroompiepojo.request.SubmitHomeworkInput;
import com.classroompie.classroompiepojo.response.GetStudentHomeworkVO;
import com.classroompie.classroompiepojo.response.GetTeacherHomeworkVO;
import com.classroompie.classroompiepojo.response.StudentHomeworkDetailVO;
import com.classroompie.classroompiepojo.response.TeacherHomeWorkDetailVO;
import com.classroompie.classroompieserver.service.HomeworkService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiahao
 * @since 2024/6/22 周六
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/homework")
public class HomeworkController {
    private final HomeworkService homeworkService;

    public HomeworkController(HomeworkService homeworkService) {
        this.homeworkService = homeworkService;
    }

    @PostMapping()
    public Result<Object> addHomework(@RequestBody @Valid AddHomeWorkInput addHomeWorkInput) {
        homeworkService.addHomework(addHomeWorkInput);
        return Result.success();
    }

    @GetMapping("/teacher/{courseId}/list")
    public Result<List<GetTeacherHomeworkVO>> getTeacherHomework(@PathVariable String courseId) {
        return Result.success(homeworkService.getTeacherHomework(courseId));
    }
    @GetMapping("/student/{courseId}/list")
    public Result<List<GetStudentHomeworkVO>> getStudentHomework(@PathVariable String courseId) {
        return Result.success(homeworkService.getStudentHomework(courseId));
    }

    @GetMapping("/correct/{homeworkId}")
    public Result<Object> getCorrectHomeworkList(@PathVariable String homeworkId) {
        return Result.success(homeworkService.getCorrectHomeworkList(homeworkId));
    }

    @PostMapping("/correct/{homeworkId}/{studentId}/{score}")
    public Result<Object> correctHomework(@PathVariable String homeworkId,@PathVariable String studentId,@PathVariable Double score) {
        homeworkService.correctHomework(homeworkId,studentId,score);
        return Result.success();
    }

    @GetMapping("/teacher/{homeworkId}")
    public Result<TeacherHomeWorkDetailVO> getTeacherHomeworkDetail(@PathVariable String homeworkId) {
        return Result.success(homeworkService.getHomeworkDetail(homeworkId));
    }

    @GetMapping("/student/{homeworkId}")
    public Result<StudentHomeworkDetailVO> getStudentHomeworkDetail(@PathVariable String homeworkId) {
        return Result.success(homeworkService.getStudentHomeworkDetail(homeworkId));
    }

    @PostMapping("/submit/{homeworkId}")
    public Result<Object> submitHomework(@PathVariable String homeworkId,@RequestBody SubmitHomeworkInput submitHomeworkInput) {
        homeworkService.submitHomework(homeworkId,submitHomeworkInput);
        return Result.success();
    }


}
